<script setup lang="ts" name="MyScores">
import { ref } from 'vue';
import { getYear } from '@/hooks/useDate';
import { ExeAssessScoresVO } from '@/api/fill/execute/scores/Types';
import { ScoreQueryDTO } from '@/api/fill/execute/budget-total/Types';
import { getBudgetDept, getMyList } from '@/api/fill/execute/scores';
import { defaultDeptName } from '@/hooks/useCommon';
import { useTableHeight } from '@/hooks/useMethod';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const loading = ref(true);
const showSearch = ref(true);
const { quarter } = toRefs<any>(proxy?.useDict('quarter'));
const queryFormRef = ref<ElFormInstance>();

//查询参数
const queryParams = ref<ScoreQueryDTO>({
  year: getYear(),
  quarter: '1',
  deptCode: undefined
});

const deptNameShow = ref(defaultDeptName);

/*用于存储表格数据*/
const tableList = ref<ExeAssessScoresVO[]>([]);

/*全部列表查询*/
const getListAll = () => {
  getBudgetDept(queryParams.value)
    .then((res) => {
      deptNameShow.value = res.data.deptName;
      queryParams.value.deptCode = res.data.deptCode;
    })
    .then(() => {
      getMyList(queryParams.value).then((res) => {
        tableList.value = res.data;
        console.log('数据：', res.data);
      });
    })
    .finally(() => {
      loading.value = false;
    });
};

/** 搜索按钮操作 */
const handleQuery = () => {
  getListAll();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryParams.value = {
    year: getYear(),
    quarter: '1',
    status: 0
  };
  handleQuery();
};

/** 导出模板按钮操作 */
const importTemplate = () => {
  // proxy?.download(
  //   '/exe/BudgetMeasure/importTemplate',
  //   {
  //     ...queryParams.value
  //   },
  //   `预算执行测算模板.xlsx`
  // );
};
/*挂载生命周期钩子*/
onMounted(() => {
  getListAll();
});

const tableStyle = useTableHeight(showSearch);
</script>

<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="never">
          <div>
            <el-form ref="queryFormRef" :inline="true">
              <el-form-item label="年度" prop="year">
                <el-date-picker type="year" format="YYYY" value-format="YYYY" v-model="queryParams.year" />
              </el-form-item>
              <el-form-item label="季度" prop="quarter">
                <el-select v-model="queryParams.quarter" placeholder="请选择季度">
                  <el-option v-for="dict in quarter" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="预算部门" prop="deptCode">
                <el-input disabled :placeholder="deptNameShow" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-card>
      </div>
    </transition>
    <el-card shadow="never">
      <template #header>

        <div style="display: flex; justify-content: space-between">
          <div>
            <el-button type="warning" icon="Download" @click="importTemplate" :loading="loading">导出</el-button>
          </div>

          <right-toolbar v-model:showSearch="showSearch" @queryTable="getListAll" />
        </div>
      </template>
      <div>
        <el-table ref="tableRef" :data="tableList" :style="tableStyle" append class="custom-table enhanced-table" border>
          <el-table-column prop="deptName" label="预算部门" align="center" width="240" show-overflow-tooltip fixed />

          <el-table-column align="center" label="预算额">
            <el-table-column prop="businessBudget" label="业务职能" align="center" width="160" />
            <el-table-column align="center" label="管理职能">
              <el-table-column prop="manageTotalBudget" label="管理合计" align="center" width="150" />
              <el-table-column prop="manageExpenseBudget" label="费用类" align="center" width="150" />
              <el-table-column prop="manageCapitalBudget" label="资本类" align="center" width="150" />
              <el-table-column prop="manageDrugBudget" label="药品" align="center" width="150" />
              <el-table-column prop="manageSuppliesBudget" label="耗材" align="center" width="150" />
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" label="执行额">
            <el-table-column prop="businessExecute" label="业务职能" align="center" width="160" />
            <el-table-column align="center" label="管理职能">
              <el-table-column prop="manageTotalExecute" label="管理合计" align="center" width="150" />
              <el-table-column prop="manageExpenseExecute" label="费用类" align="center" width="150" />
              <el-table-column prop="manageCapitalExecute" label="资本类" align="center" width="150" />
              <el-table-column prop="manageDrugExecute" label="药品" align="center" width="150" />
              <el-table-column prop="manageSuppliesExecute" label="耗材" align="center" width="150" />
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" label="执行率">
            <el-table-column prop="businessRate" label="业务职能" align="center" width="160" />
            <el-table-column align="center" label="管理职能">
              <el-table-column prop="manageTotalRate" label="管理合计" align="center" width="150" />
              <el-table-column prop="manageExpenseRate" label="费用类" align="center" width="150" />
              <el-table-column prop="manageCapitalRate" label="资本类" align="center" width="150" />
              <el-table-column prop="manageDrugRate" label="药品" align="center" width="150" />
              <el-table-column prop="manageSuppliesRate" label="耗材" align="center" width="150" />
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" label="偏差率">
            <el-table-column prop="businessDeviation" label="业务职能" align="center" width="160" />
            <el-table-column align="center" label="管理职能">
              <el-table-column prop="manageTotalDeviation" label="管理合计" align="center" width="150" />
              <el-table-column prop="manageExpenseDeviation" label="费用类" align="center" width="150" />
              <el-table-column prop="manageCapitalDeviation" label="资本类" align="center" width="150" />
              <el-table-column prop="manageDrugDeviation" label="药品" align="center" width="150" />
              <el-table-column prop="manageSuppliesDeviation" label="耗材" align="center" width="150" />
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" label="得分">
            <el-table-column prop="businessScore" label="业务职能" align="center" width="160" />
            <el-table-column align="center" label="管理职能">
              <el-table-column prop="manageTotalScore" label="管理合计" align="center" width="150" />
              <el-table-column prop="manageExpenseScore" label="费用类" align="center" width="150" />
              <el-table-column prop="manageCapitalScore" label="资本类" align="center" width="150" />
              <el-table-column prop="manageDrugScore" label="药品" align="center" width="150" />
              <el-table-column prop="manageSuppliesScore" label="耗材" align="center" width="150" />
            </el-table-column>
            <el-table-column prop="totalScore" label="总得分" align="center" width="160" />
          </el-table-column>

          <el-table-column prop="appealReason" align="center" label="申诉原因" width="350" show-overflow-tooltip />
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<style scoped lang="scss"></style>
